package me.xplabs.fight 
{
	import flash.display.BitmapData;
	import me.xplabs.fight.layer.FlagLayer;
	import me.xplabs.Globals;
	import me.xplabs.engine.display.BaseAnimate;
	import me.xplabs.engine.display.BaseDisplayContainer;
	import me.xplabs.fight.layer.BackgroundLayer;
	import me.xplabs.fight.layer.BuildLayer;
	import me.xplabs.fight.layer.EffectLayer;
	import me.xplabs.fight.layer.RoleLayer;
	import me.xplabs.magic.LongDistanceMagic;
	import me.xplabs.model.combatunit.MBuildInfo;
	import me.xplabs.model.combatunit.MFlagInfo;
	import me.xplabs.model.combatunit.MRoleInfo;
	import me.xplabs.model.msg.MsgUseSkill;
	import me.xplabs.model.skill.MSkillInfo;
	import me.xplabs.msg.NotificationFight;
	import me.xplabs.msg.NotificationName;
	import me.xplabs.utils.Utils;
	import org.puremvc.as3.interfaces.INotification;
	
	/**
	 * 战斗界面地图渲染管理
	 * ...
	 * @author xiaohan
	 */
	public class MapManager extends BaseDisplayContainer 
	//public class MapManager extends BaseAnimate 
	{
		//背景图层
		//private var _backgroundLayer:BackgroundLayer;
		//建筑图层
		private var _buildLayer:BuildLayer;
		//角色图层
		private var _roleLayer:RoleLayer;
		//特效图层
		private var _effectLayer:EffectLayer;
		//旗帜图层
		private var _flagLayer:FlagLayer;
		private var _frameIndex:int;
		public function MapManager() 
		{
			super();
			
			//_backgroundLayer = new BackgroundLayer();
			_buildLayer = new BuildLayer();
			_flagLayer = new FlagLayer();
			_roleLayer = new RoleLayer();
			_effectLayer = new EffectLayer();
			//addChild(_backgroundLayer);
			addChild(_buildLayer);
			addChild(_flagLayer);
			addChild(_roleLayer);
			addChild(_effectLayer);
		}
		/*override public function update(container:BitmapData):void 
		{
			_frameIndex++;
			if (_frameIndex == 1) super.update(container);
			else if (_frameIndex  == 4)  _frameIndex = 0;
		}*/
		public function handleNotification(notification:INotification):void 
		{
			switch(notification.getType())
			{
				case NotificationFight.CHANGE_FIGHT:
					//_backgroundLayer.setBackground(Globals.lib.getResObj(Globals.domain.background + notification.getBody()));
					//_backgroundLayer.setBackground(Globals.lib.getResObj(Globals.domain.background + notification.getBody()));
					break;
				case NotificationFight.APPEAR_ENERGY:
					_roleLayer.addActor(MRoleInfo(notification.getBody()));
					break;
				case NotificationFight.DISAPPEAR_ENERGY:
					_roleLayer.delActor(int(notification.getBody()));
					break;
				case NotificationFight.INIT_BUILD_LIST:
					//_buildLayer.initBuildList(Vector.<MBuildInfo>(notification.getBody()));
					break;
				case NotificationFight.UPGRADE_BUILD_COMPLETE:
					_buildLayer.upgradeBuild(MBuildInfo(notification.getBody()));
					break;
				case NotificationFight.DESTORY_BUILD_COMPLETE:
					_buildLayer.destoryBuilding(MBuildInfo(notification.getBody()));
					break;
				case NotificationFight.ADD_BUILD_COMPLETE:
					_buildLayer.addBuilding(MBuildInfo(notification.getBody()));
					break;
				case NotificationFight.HIT_ACTOR:
					break;
				case NotificationFight.USE_SKILL:
					//_effectLayer.addMagic(LongDistanceMagic(notification.getBody()));
					break;
				case NotificationFight.REMOVE_HIT_EFFECT:
					_effectLayer.removeMagic(int(notification.getBody()));
					break;
				case NotificationFight.REMOVE_BUILDING:
					_buildLayer.delBuilding(int(notification.getBody()));
					break;
				case NotificationFight.ADD_FLAG_COMPLETE:
					_flagLayer.addFlag(MFlagInfo(notification.getBody()));
					break;
				case NotificationFight.REMOVE_FLAG_COMPLETE:
					_flagLayer.delFlag(int(notification.getBody()));
					break;
				case NotificationFight.ADD_BUFF:
					print("添加到显示对象到特效层");
					break;
				case NotificationFight.DEL_BUFF:
					print("移除显示对象上的buff");
					break;
				
			}
		}
		override public function dispose():void 
		{
			super.dispose();
		}
	}
}